package array;

public class leetCode75_sortColors {

    public void sortColors(int[] nums) {
        int len = nums.length;
        if(len < 2) return;

        int left = 0; // 0的右边界
        int right = len - 1; // 2的左边界
        int i = 0;
        while (i <= right){
            if(nums[i] == 0){
                swap(nums,i++,left++);
            }else if(nums[i] == 1){
                i++;
            }else{
                swap(nums,i,right--);
            }
        }

    }

    public void swap(int[] nums,int i,int j){
        int tmp = nums[i];
        nums[i] = nums[j];
        nums[j] = tmp;
    }

}
